﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Memo.Electricity.Engine;

namespace Memo.Electricity.Game
{
	public class CClock : CBaseOrderBlock
	{
		private Material material;
		private float offset
		{
			get
			{
				return material.GetFloat("_AlphaOffSetY");
			}
			set
			{
				material.SetFloat("_AlphaOffSetY", value);
			}
		}

		private void Awake()
		{
			material = GetComponent<SpriteRenderer>().material;
		}

		public void Enabled()
		{
			StartCoroutine(EnableCoroutine());
		}

		public void Disabled()
		{
			StartCoroutine(DisableCoroutine());
		}

		private IEnumerator EnableCoroutine()
		{
			gameObject.SetActive(true);

			offset = 0;
			while (offset < 1)
			{
				offset += 5 * Time.deltaTime;
				if (offset >= 1)
				{
					offset = 1;
				}
				else
				{
					yield return null;
				}
			}
		}

		private IEnumerator DisableCoroutine()
		{
			offset = 1;
			while (offset > 0)
			{
				offset -= 5 * Time.deltaTime;
				if (offset <= 0)
				{
					offset = 0;
				}
				else
				{
					yield return null;
				}
			}
			gameObject.SetActive(false);
		}
	}
}
